package com.bean.activiti.activiti.entity.manager;

import com.bean.activiti.entity.SysRole;
import com.bean.activiti.entity.SysUser;
import com.bean.activiti.mapper.SysRoleMapper;
import com.bean.activiti.mapper.SysUserMapper;
import com.bean.activiti.util.ActivitiUtil;
import org.activiti.engine.identity.*;
import org.activiti.engine.impl.GroupQueryImpl;
import org.activiti.engine.impl.Page;
import org.activiti.engine.impl.interceptor.Session;
import org.activiti.engine.impl.persistence.entity.*;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.util.List;
import java.util.Map;

/**
 * @author Gavin Lee
 * @version 1.0
 * @date 2020-9-11 9:23
 * @desc
 */
@Component
public class CustomGroupEntityManager implements GroupEntityManager, Session {

    @Autowired
    private SysUserMapper sysUserMapper;

    @Autowired
    private SysRoleMapper sysRoleMapper;

    @Override
    public void flush() {

    }

    @Override
    public void close() {

    }

    @Override
    public Group createNewGroup(String s) {
        throw new RuntimeException("not implement method.");
    }

    @Override
    public GroupQuery createNewGroupQuery() {
        throw new RuntimeException("not implement method.");
    }

    @Override
    public List<Group> findGroupByQueryCriteria(GroupQueryImpl groupQuery, Page page) {
        throw new RuntimeException("not implement method.");
    }

    @Override
    public long findGroupCountByQueryCriteria(GroupQueryImpl groupQuery) {
        throw new RuntimeException("not implement method.");
    }

    @Override
    public List<Group> findGroupsByUser(String userId) {
        if (userId == null)
            return null;
        SysUser sysUser = sysUserMapper.selectUserByLoginName(userId);
        List<SysRole> sysRoleList = sysRoleMapper.selectRolesByUserId(sysUser.getUserId());
        if (sysRoleList != null && sysRoleList.size() > 0) {
            return ActivitiUtil.toActivitiGroups(sysRoleList);
        }
        return null;
    }

    @Override
    public List<Group> findGroupsByNativeQuery(Map<String, Object> map, int i, int i1) {
        throw new RuntimeException("not implement method.");
    }

    @Override
    public long findGroupCountByNativeQuery(Map<String, Object> map) {
        throw new RuntimeException("not implement method.");
    }

    @Override
    public boolean isNewGroup(Group group) {
        throw new RuntimeException("not implement method.");
    }

    @Override
    public GroupEntity create() {
        throw new RuntimeException("not implement method.");
    }

    @Override
    public GroupEntity findById(String s) {
        throw new RuntimeException("not implement method.");
    }

    @Override
    public void insert(GroupEntity entity) {
        throw new RuntimeException("not implement method.");
    }

    @Override
    public void insert(GroupEntity entity, boolean b) {
        throw new RuntimeException("not implement method.");
    }

    @Override
    public GroupEntity update(GroupEntity entity) {
        throw new RuntimeException("not implement method.");
    }

    @Override
    public GroupEntity update(GroupEntity entity, boolean b) {
        throw new RuntimeException("not implement method.");
    }

    @Override
    public void delete(String s) {
        throw new RuntimeException("not implement method.");
    }

    @Override
    public void delete(GroupEntity entity) {
        throw new RuntimeException("not implement method.");
    }

    @Override
    public void delete(GroupEntity entity, boolean b) {
        throw new RuntimeException("not implement method.");
    }

    /*@Override
    public List<Group> findGroupsByUser(final String userCode) {
        if (userCode == null)
            return null;
        SysUser sysUser = new SysUser();
        sysUser.setLoginName(userCode);
        List<SysUser> sysUserList = sysUserMapper.selectUserList(sysUser);
        if (sysUserList != null && sysUserList.size() > 0) {
            return ActivitiUtil.toActivitiGroups(sysUserList.get(0).getRoles());
        }
        return null;
    }*/

}
